/**
 * Created by songj on 2015/12/11.
 */
define(['angular',
    'framework/msg/GillionMsgModule',
    'framework/dataGrid/DataGridModule',
    'framework/pagination/GillionPaginationModule',
    'framework/datasource/DataSourceModule',
    'framework/dropdown/GillionDropdownModule',
    'framework/date/DateModule',
    'angular-underscore'
], function (angular) {
    var module = angular.module('UnitController',
        ['GillionMsgModule', 'DataGridModule', 'GillionPaginationModule',
            'DataSourceModule', 'DateModule', 'GillionDropdownModule'])
        .controller('UnitController', ['$scope', 'GillionMsgService', '$dataSourceManager', '$timeout', 'Arrays', "$location",'Resource','GillionMsg','$compile','$http',
                function ($scope, GillionMsgService, $dataSourceManager, $timeout, Arrays, $location,Resource,GillionMsg) {
                    $scope.unitCase = GillionMsgService.getInputData();
                    angular.element('input[name="unitCaseName"]').focus();
                    $scope.search = {
                        unitCase:  $scope.unitCase
                    };
                    var unitCaseResource = Resource("/grule-manager/unitcases", {
                    });
                    $scope.submit=function(){
                        $scope.UnitCaseForm.verify().then(function(){
                            unitCaseResource.create($scope.unitCase,function(response){
                                if (response.success) {
                                    GillionMsgService.setOutputData(response);
                                    GillionMsgService.close();
                                }
                            })
                        });
                    }
                    $scope.cancel = function(){
                        GillionMsgService.close();
                    }
                }
            ]
        );

    module.config(['$locationProvider', function($locationProvider) {
        $locationProvider.html5Mode(true);
    }]);
    return module;
});
